package com.zhixin.fans.ks.ui.charge;

import android.view.View;
import android.widget.TextView;

import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton;
import com.zhixin.fans.ks.R;
import com.zhixin.fans.ks.api.CommonApi;
import com.zhixin.fans.ks.api.res.FirstChargeRes;
import com.zhixin.fans.ks.manager.UserInfoManager;
import com.zhixin.fans.ks.ui.base.BaseNeedLoginActivity;

import org.eenie.common.subscribes.ProgressSubscriber;
import org.eenie.common.views.TopBarLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class FirstChargeActivity extends BaseNeedLoginActivity {
    public static final String ROUTE_PATH = "/charge/first_charge";

    @BindView(R.id.top_bar)
    TopBarLayout mTopBar;


//    CoupleApi mCoupleApi;
    UserInfoManager mUserInfoManager;
    @BindView(R.id.tv_pay_count)
    TextView mTvPayCount;
    @BindView(R.id.btn_buy)
    QMUIRoundButton mBtnBuy;

    CommonApi mCommonApi;

    @Override
    public int initContentView() {
        return R.layout.activity_first_charge;
    }

    @Override
    public void initInjector() {
        mCommonApi = getApplicationComponent().getApiManager().create(CommonApi.class);
        mUserInfoManager = getCoupleAppComponent().getUserInfoManager();
    }

    @Override
    public void initUiAndListener() {
        ButterKnife.bind(this);
        mTopBar.addLeftBackImageButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });


        fetchFirstChange();
    }


    private void fetchFirstChange() {
        mCommonApi.fetchFirstChangePay()
                .subscribe(new ProgressSubscriber<FirstChargeRes>() {
                    @Override
                    public void onNext(FirstChargeRes firstChargeRes) {
                        mTvPayCount.setText(String.format("￥%s", firstChargeRes.getMoney()));
                    }

                    @Override
                    public void onFinish() {

                    }
                });
    }


    @OnClick(R.id.btn_buy)
    public void buy() {
//        mCommonApi.fetchFirstChangePay(mUserInfoManager.getValue().getU_id())
//                .subscribe(new ProgressSubscriber<PayInfoRes>(mContext) {
//                    @Override
//                    public void onNext(PayInfoRes payInfoRes) {
//                        PayUtil.payWx(mContext, payInfoRes.getWxpay());
//                    }
//
//                    @Override
//                    public void onFinish() {
//
//                    }
//                });
    }
}
